import {defineStore} from 'pinia'
import {ref,computed} from 'vue'

export const useUserStore = defineStore('user',()=>{

    const userInfo=ref({})
    const token=ref('')

    //获取本地登录信息
    const getUserInfo=()=>{
        return JSON.stringify(userInfo.value)==='{}'?null:userInfo.value
    }

    //装载登录信息
    const setUserInfo=(user)=>{
        userInfo.value=user
    }

    //清除登录信息
    const clearUserInfo=()=>{
        userInfo.value={}
        token.value=''
    }

    function getToken() {
        return token.value
    }

    function setToken(data) {
        token.value=data
    }

    return{
        userInfo,
        getUserInfo,
        setUserInfo,
        clearUserInfo,
        token,
        getToken,
        setToken,
    }
},
    {
        //持久化存储
        persist: true
    }
)